﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Web.Caching;

namespace eDoc.BO
{
    public class Cached
    {
        public class CacheName
        {
            public static string Cache_Select_User_Menu(string user)
            {
                return "Cache_Select_User_Menu_" + user;
            }

            public static string Cache_Select_Menu_by_User(string Username)
            {
                return "Select_Menu_by_User_" + Username;
            }
        }
        /// <summary>
        /// Luu cache
        /// </summary>
        /// <param name="data"></param>
        /// <param name="cacheKey"></param>
        public static void SetCache(string cacheName, object data)
        {
            HttpContext.Current.Cache.Insert(cacheName, data, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration);
        }

        public static void RemoveCache(string cacheName)
        {
            HttpContext.Current.Cache.Remove(cacheName);
        }


        public static T GetCache<T>(string cacheName) where T : class
        {
            object obj = HttpContext.Current.Cache.Get(cacheName);
            return (T)obj;
            
        }
    }
}
